package com.agency8x.model;

import com.agency8x.model.base.BaseLoginLogModel;
import com.agency8x.util.DateTimeUtil;
import com.agency8x.util.RegexUtil;
import com.jfinal.plugin.activerecord.Page;

public class LoginLogModel extends BaseLoginLogModel<LoginLogModel> {

	private static final long serialVersionUID = 1L;
	public static final LoginLogModel me = new LoginLogModel().dao();

	/**
	 * 所有 sql 与业务逻辑写在 Service 中，在此放在 Model 中仅为示例
	 */
	public Page<LoginLogModel> paginate(int pageNumber, int pageSize, String where) {
		String sql = "select * ";
		String sqlFrom = "from t_log_login ";
		if (where != null && !"".equals(where.trim())) {
			if (RegexUtil.isNumeric(where))
				sqlFrom = sqlFrom + "where user_id = " + where;
		}
		return paginate(pageNumber, pageSize, sql, sqlFrom);
	}

	public Page<LoginLogModel> getPaginateByUserId(int pageNumber, int pageSize, Integer user_id) {
		String sql = "select * ";
		String sqlFrom = "from t_log_login ";
		if (user_id > 0) {
			sqlFrom = sqlFrom + "where user_id = " + user_id;
		}
		return paginate(pageNumber, pageSize, sql, sqlFrom);
	}
    public String getLoginTimeText(){
        return DateTimeUtil.formatSqlServerDateTime(getLoginTime());
    }
}
